#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

int show()
{
  printf("hello show()!\n");
  _exit(12);
  //return 0;
}

int main()
{
  pid_t ids[10];
  for(int i = 0;i < 10;i++) {
    pid_t id = fork();
    if(id == 0) {
      //child
      int count = 0;
      while(count < 10) {
        printf("child do something!:%d,%d\n",getpid(),getppid());
        count++;
        sleep(1);
      }
      exit(i);
    }
    //father
    ids[i] = id;
  }
  int count = 0;
  while(count < 10) {
    int status = 0;
    pid_t ret = waitpid(ids[count],&status,0);
    if(ret >= 0) {
      printf("wait child success!,%d\n",ret);
      printf("child get signal:%d\n",WEXITSTATUS(status));
     // printf("status:%d\n",status);
     // printf("child exit code:%d\n",(status>>8)&0xFF);
     // printf("child get signal:%d\n",status&0x7F);
    }
    count++;
  }



  //if(id == 0) {
  //  //child
  //  int count = 0;
  //  while(count < 30) {
  //    printf("I am child,pid:%d,ppid:%d\n",getpid(),getppid());
  //    if(count == 10) {
  //     // int a = 1/0;
  //      int *p;
  //      *p = 100;
  //    }
  //    sleep(1);
  //    count++;
  //  }
  //  exit(0);
  //}
  //else {
  //  //father
  //  printf("I am father,pid:%d,ppid:%d\n",getpid(),getppid());
  //  //pid_t ret = wait(NULL);
  //  int status = 0;
  //  pid_t ret = waitpid(id,&status,0);
  //  if(ret >= 0) {
  //    printf("wait child success!,%d\n",ret);
  //    printf("status:%d\n",status);
  //    printf("child exit code:%d\n",(status>>8)&0xFF);
  //    printf("child get signal:%d\n",status&0x7F);
  //  }
  //  printf("Father is run....\n");
  //  sleep(5);
  //}

 // for(int i = 0;i < 134;i++){
 //   printf("%d:%s\n",i,strerror(i));
 // }
 // show();
 // 
 // printf("process is not done!\n");
 // return 11;
}
